package com.investment.advisor.repository;

import com.investment.advisor.entity.Portfolio;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface PortfolioRepository extends JpaRepository<Portfolio, Long> {
    // 根据名称精确查找
    Portfolio findByName(String name);
    
    // 根据名称模糊查询
    List<Portfolio> findByNameContaining(String keyword);
    
    @Query("SELECT p FROM Portfolio p WHERE p.strategy.id = :strategyId")
    List<Portfolio> findByStrategyId(@Param("strategyId") Long strategyId);
    
    @Query("SELECT p FROM Portfolio p JOIN p.portfolioFunds pf WHERE pf.fund.id = :fundId")
    List<Portfolio> findByFundId(@Param("fundId") Long fundId);
    
    List<Portfolio> findByCreator(String creator);
} 